package com.nursinghome.user.service.impl;

import com.nursinghome.admin.mapper.AccountMapper;
import com.nursinghome.bean.Account;
import com.nursinghome.exception.NurisingHomeException;
import com.nursinghome.user.mapper.UserAccountMapper;
import com.nursinghome.user.service.UserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserAccountServiceImpl implements UserAccountService {
    @Autowired
    private UserAccountMapper userAccountMapper;
    @Autowired
    private AccountMapper accountMapper;
    @Override
    public List<Account> selectByadata(String data, Long eid) {
        return userAccountMapper.selectByadata(data, eid);
    }

    @Override
    public Boolean updateAccountElderly(Long aid) throws NurisingHomeException {
        Account account = accountMapper.selectByAid(aid);
        if (account.getAstate() == 2){
            throw new NurisingHomeException("支付失败，该账单已经支付过");
        }
        return userAccountMapper.updateAccountByElderly(aid) == 1;
    }
}
